﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using VisaCRM.Modules.Admin.Model;
using VisaCRM.Common.Helper;

namespace VisaCRM.Modules.Admin.Gateway
{
    class ProductTypesGateway
    {
        public ObservableCollection<ProductTypes> GetAllproducttypes()
        {
            ObservableCollection<ProductTypes> allProductType = new ObservableCollection<ProductTypes>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchProductTypesList());
            if (dt.Rows.Count <= 0)
            {
                return allProductType;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allProductType.Add(new ProductTypes()
                {
                    ProductTypeID = Convert.ToInt32(dataRow["ProductType_ID"].ToString()),
                    ProductTypeName = dataRow["ProductType_Name"].ToString(),
                    ProductTypeDestinationID = Convert.ToInt32( dataRow["ProductType_DestinationID"].ToString()),
                    ProductTypeDepartmentID= Convert.ToInt32( dataRow["ProductType_DepartmentID"].ToString()),
                    ProductTypeStageDiagramID= Convert.ToInt32( dataRow["ProductType_StageDiagramID"].ToString()),
                    ProductTypeMFBGroupID= Convert.ToInt32( dataRow["ProductType_MFBGroupID"].ToString()),
                    ProductTypeSLSID= Convert.ToInt32( dataRow["ProductType_SLSID"].ToString()),
                    ProductTypeChargeGroupID= Convert.ToInt32( dataRow["ProductType_ChargeGroupID"].ToString()),
                    ProductTypeEventGroupID= Convert.ToInt32( dataRow["ProductType_EventGroupID"].ToString()),
                    ProductTypeWebLoopID= Convert.ToInt32( dataRow["ProductType_WebLoopID"].ToString()),
                    ProductTypeFastTrack= Convert.ToInt32( dataRow["ProductType_FastTrack"].ToString()),
                    ProductTypeDTCategory= Convert.ToInt32( dataRow["ProductType_DTCategory"].ToString()),
                    ProductTypeCalcSet= Convert.ToInt32( dataRow["ProductType_CalcSet"].ToString()),
                    ProductTypeTargetGroupID= Convert.ToInt32( dataRow["ProductType_TargetGroupID"].ToString()),
                    ProductTypeDTDisabled= (DateTime) dataRow["PRODUCTTYPE_DTDISABLED"],
                    ProductTypeResidenceID= Convert.ToInt32( dataRow["ProductType_ResidenceID"].ToString()),
                    ProductTypeBranchID = Convert.ToInt32(dataRow["ProductType_BranchID"].ToString())
                });
            }
            return allProductType;
        }

        public void SaveNewProductTypeToDatabase(string productname, int desId, int depId, int stgId, int cgId, int egId, int BId, int resId)
        {
            string query = QueryProvider.MakeSQLQueryToInsertProductTypeToDatabase(productname,desId,depId,stgId,cgId,egId,BId,resId);
            DBHelper.ExecuteSqlQuery(query);
        }

        public void EditProductTypeToDatabase(int rowid, string productname, int desId, int depId, int stgId, int cgId, int egId, int BId, int resId)
        {
            string query = QueryProvider.MakeSQLQueryToEditProductTypeToDatabase(rowid, productname, desId, depId, stgId, cgId, egId, BId, resId);
            DBHelper.ExecuteSqlQuery(query);

        }

        public void DeleteProductTypeFromDatabase(string name)
        {
            string query = QueryProvider.MakeSQLQueryToDeleteProductTypeFromDatabase(name);
            DBHelper.ExecuteSqlQuery(query);
        }





        internal Country GetCurrentDestination(int id)
        {
            Country destination = new Country();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchCurrentDestination(id));
            if (dt.Rows.Count <= 0)
            {
                return destination;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                destination.CountryId = dataRow["Country_ID"].ToString();
                destination.CountryName = dataRow["Country_Name"].ToString();
            }
            return destination;
        }

        internal ObservableCollection<StageDiagram> GetAllStageDiagram()
        {
            ObservableCollection<StageDiagram> allStageDiagram = new ObservableCollection<StageDiagram>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchStageDiagramList());
            if (dt.Rows.Count <= 0)
            {
                return allStageDiagram;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allStageDiagram.Add(new StageDiagram()
                {
                    StageDiagramID = Convert.ToInt32(dataRow["StageDiagram_ID"].ToString()),
                    StageDiagramName = dataRow["StageDiagram_Name"].ToString()
                    
                });
            }
            return allStageDiagram;
        }

        internal StageDiagram GetCurrentStagediagram(int id)
        {
            StageDiagram stagediagram = new StageDiagram();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchCurrentStageDiagram(id));
            if (dt.Rows.Count <= 0)
            {
                return stagediagram;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                stagediagram.StageDiagramID = Convert.ToInt32(dataRow["StageDiagram_ID"].ToString());
                stagediagram.StageDiagramName = dataRow["StageDiagram_Name"].ToString();
            }
            return stagediagram;
        }

        internal ObservableCollection<ChargeGroup> GetAllChargeGroups()
        {
            ObservableCollection<ChargeGroup> allChargegroup = new ObservableCollection<ChargeGroup>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchChargeGroupList());
            if (dt.Rows.Count <= 0)
            {
                return allChargegroup;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allChargegroup.Add(new ChargeGroup()
                {
                    ChargeGroupID = Convert.ToInt32(dataRow["ChargeGroup_ID"].ToString()),
                    ChargeGroupName = dataRow["ChargeGroup_Name"].ToString()

                });
            }
            return allChargegroup;
        }

        internal ChargeGroup GetCurrentChargeGroup(int id)
        {
            ChargeGroup chargegroup = new ChargeGroup();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchCurrentChargeGroup(id));
            if (dt.Rows.Count <= 0)
            {
                return chargegroup;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                chargegroup.ChargeGroupID = Convert.ToInt32(dataRow["ChargeGroup_ID"].ToString());
                chargegroup.ChargeGroupName = dataRow["ChargeGroup_Name"].ToString();
            }
            return chargegroup;
        }

        internal ObservableCollection<EventGroup> GetAllEventgroup()
        {
            ObservableCollection<EventGroup> alleventgroup = new ObservableCollection<EventGroup>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchEventGroupList());
            if (dt.Rows.Count <= 0)
            {
                return alleventgroup;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                alleventgroup.Add(new EventGroup()
                {
                    EventGroupID = Convert.ToInt32(dataRow["EventGroup_ID"].ToString()),
                    EventGroupName = dataRow["EventGroup_Name"].ToString()

                });
            }
            return alleventgroup;
        }

        

        internal EventGroup GetCurrentEventGroup(int id)
        {
            EventGroup eventgroup = new EventGroup();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchCurrentEventGroup(id));
            if (dt.Rows.Count <= 0)
            {
                return eventgroup;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                eventgroup.EventGroupID = Convert.ToInt32(dataRow["EventGroup_ID"].ToString());
                eventgroup.EventGroupName = dataRow["EventGroup_Name"].ToString();
            }
            return eventgroup;
        }
    }
}
